package com.water.wfo.user.ability.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.water.wfo.sys.pojo.entity.BulletinEntiy;
import com.water.wfo.sys.pojo.entity.ParameterEntity;
import com.water.wfo.sys.pojo.request.DataDictionaryRequest;
import com.water.wfo.sys.pojo.response.ParameterResponse;
import com.water.wfo.user.ability.BulletinAbility;
import com.water.wfo.user.mapper.BulletinMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 系统公告表 服务实现类
 * </p>
 *
 * @author water&7
 * @since 2024-07-24
 */
@Slf4j
@Component
public class BulletinAbilityImpl implements BulletinAbility {
    @Autowired
    private BulletinMapper bulletinMapper;

    @Override
    public int insert(BulletinEntiy entity) {
        return bulletinMapper.insert(entity);
    }

    @Override
    public int update(BulletinEntiy entity) {
        return bulletinMapper.update(entity);
    }

    @Override
    public BulletinEntiy selectById(Long id) {
        return bulletinMapper.selectById(id);
    }

    @Override
    public BulletinEntiy selectByEntity(BulletinEntiy entiy) {
        return bulletinMapper.selectByEntity(entiy);
    }

    @Override
    public ParameterResponse queryBulletinListBy(DataDictionaryRequest entity) {
        List<BulletinEntiy> bulletinEntiys = null;
        try {
            PageHelper.startPage(entity.getPageNum(),entity.getPageSize());
            bulletinEntiys = bulletinMapper.queryBulletinEntityBy(entity);
        } catch (Exception e) {
            log.error(e.getMessage());
        } finally {
            PageHelper.clearPage();
        }
        //得到分页的结果对象
        PageInfo<BulletinEntiy> personPageInfo = new PageInfo<>(bulletinEntiys);
        //得到分页中条目对象
        List<BulletinEntiy> pageList = personPageInfo.getList();
        ParameterResponse response = new ParameterResponse();
        response.setResult(pageList);
        response.setTotal(personPageInfo.getTotal());
        return response;
    }

    @Override
    public int deleteBatchByIds(List<Long> list) {
        return bulletinMapper.deleteBatchByIds(list);
    }
}
